# coding = utf-8

'''
分析图像的插值变换
'''

import cv2,os
import numpy as np
import matplotlib.pyplot as plt
import SimpleITK as sitk
from PIL import Image
import math

def read_data():
    def find_data(case_id, origion_id, index):
         big_image = "E:\Dataset\Liver\qiye\DongBeiDaXue2\image_venous\\data2_{}_venous.mha".format(origion_id)
         big_liver = "E:\Dataset\Liver\qiye\DongBeiDaXue2\liver\\data2_{}_liver_label.mha".format(origion_id)
         big_tumor = "E:\Dataset\Liver\qiye\DongBeiDaXue2\lesion\\data2_{}_lesion_label.mha".format(origion_id)
         big_fusion = "E:\predict\image_tumor\case_{}\\fusion\\{}.png".format(str(case_id).zfill(5), str(index).zfill(3))
         big_image = sitk.GetArrayFromImage(sitk.ReadImage(big_image))
         big_image[big_image<=-200] = -200
         big_image[big_image > 250] = 250
         #big_image = (big_image+200) / 450
         big_image = big_image[index]
         big_liver = sitk.GetArrayFromImage(sitk.ReadImage(big_liver))
         big_liver = big_liver[index]
         big_tumor = sitk.GetArrayFromImage(sitk.ReadImage(big_tumor))
         big_tumor = big_tumor[index]
         big_fusion = Image.open(big_fusion)
         return (big_image, big_fusion, big_liver, big_tumor)

    (big_image, big_fusion, big_liver, big_tumor) = find_data(case_id=74, origion_id="0656", index=40)
    (middle_image, middle_fusion, middle_liver, middle_tumor) = find_data(case_id=67, origion_id="0415", index=135)
    (small_image, small_fusion, small_liver, small_tumor) = find_data(case_id=79, origion_id="0865", index=262)
    (little_image, little_fusion, little_liver, little_tumor) = find_data(case_id=72, origion_id="0628", index=142)
    (small_image2, small_fusion, small_liver, small_tumor) = find_data(case_id=79, origion_id="0865", index=263)

    plt.subplot(2, 2, 1)
    plt.imshow(small_image, cmap="gray")
    plt.subplot(2,2, 2)
    plt.imshow(small_image2, cmap="gray")
    plt.subplot(2, 2, 3)
    plt.imshow(small_fusion)
    plt.subplot(2, 2, 4)
    plt.imshow(abs(small_image2-small_image), cmap="gray")
    plt.show()



if __name__ == '__main__':
    read_data()